<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    <title> - 天地维杰网</title>
    <meta name="keywords" content="系统架构,shutdown,不与天斗,Domino,博客,程序员,架构师,笔记,技术,分享,java,Redis">
    
    <meta property="og:title" content="">
    <meta property="og:site_name" content="天地维杰网">
    <meta property="og:image" content="/img/author.jpg"> 
    <meta name="title" content=" - 天地维杰网" />
    <meta name="description" content="天地维杰网 | 博客 | 软件 | 架构 | Java "> 
    <link rel="shortcut icon" href="http://www.shutdown.cn/img/favicon.ico" />
    <link rel="apple-touch-icon" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link rel="apple-touch-icon-precomposed" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link href="http://www.shutdown.cn/js/vendor/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/main.css" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/syntax.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
     fancybox: true, 
    motion: true
  };
</script>
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7826003325059020" crossorigin="anonymous"></script>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container one-collumn sidebar-position-left page-home  ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-meta  custom-logo ">

  <div class="custom-logo-site-title">
    <a href="http://www.shutdown.cn"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">天地维杰网</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">人如秋鸿来有信，事若春梦了无痕</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
    <ul id="menu" class="menu">
      
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/redis/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-full"></i> <br />Redis
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/java/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-coffee"></i> <br />java
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/linux/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-linux"></i> <br />linux
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/daily/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bug"></i> <br />日常问题
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/spring/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-child"></i> <br />Spring和Springboot
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/mac/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-fire"></i> <br />Mac相关
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/middleware/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-gavel"></i> <br />中间件
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jiagou/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-rocket"></i> <br />架构
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/python/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-ship"></i> <br />python
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/front/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bolt"></i> <br />前端
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jvm/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-balance-scale"></i> <br />jvm
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/c/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-empty"></i> <br />c语言
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/web3/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-web3"></i> <br />web3
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/post/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/about/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于
          </a>
        </li>
      
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger"> <i class="menu-item-icon fa fa-search fa-fw"></i> <br /> 搜索</a>
      </li>
    </ul>
    <div class="site-search">
      <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>

    </div>
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
<section id="posts" class="posts-expand">
  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/redis5.0%E7%89%88%E6%9C%AC%E4%BB%8B%E7%BB%8D/" itemprop="url">
        
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="0001-01-01">
    0001-01-01
</time>
</span> 
      
      
       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">669 字 ~4分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    

    

<h1 id="introduction-to-the-redis-5-release">Introduction to the Redis 5 release</h1>

<p>Redis 5 is a release focused on a few important features. While Redis 4
was very very focused on operations, Redis 5 changes are mostly user-facing,
with the implementation of new data types and operations on top of existing
types. The following are the major features of this release:</p>

<blockquote>
<p>Redis5是一个聚焦到几个重要改进的版本。Redis4是非常关注操作，Redis5改进是非常关注用户界面，
新增了新的数据类型的实现和现有数据类型的相关操作。</p>
</blockquote>

<ol>
<li>The new Stream data type. <a href="https://redis.io/topics/streams-intro">https://redis.io/topics/streams-intro</a></li>
<li>New Redis modules APIs: Timers, Cluster and Dictionary APIs.</li>
<li>RDB now store LFU and LRU information.</li>
<li>The cluster manager was ported from Ruby (redis-trib.rb) to C code
inside redis-cli. Check <code>redis-cli --cluster help</code> for more info.</li>
<li>New sorted set commands: ZPOPMIN/MAX and blocking variants.</li>
<li>Active defragmentation version 2.</li>
<li>Improvemenets in HyperLogLog implementations.</li>
<li>Better memory reporting capabilities.</li>
<li>Many commands with sub-commands now have an HELP subcommand.</li>
<li>Better performances when clients connect and disconnect often.</li>
<li>Many bug fixes and other random improvements.</li>
<li>Jemalloc was upgraded to version 5.1</li>
<li>CLIENT UNBLOCK and CLIENT ID.</li>
<li>The LOLWUT command was added. <a href="http://antirez.com/news/123">http://antirez.com/news/123</a></li>
<li>We no longer use the &ldquo;slave&rdquo; word if not for API backward compatibility.</li>
<li>Differnet optimizations in the networking layer.</li>
<li>Lua improvements:

<ul>
<li>Better propagation of Lua scripts to slaves / AOF.</li>
<li>Lua scripts can now timeout and get in -BUSY state in the slave as well.</li>
</ul></li>
<li>Dynamic HZ to balance idle CPU usage with responsiveness.</li>
<li>The Redis core was refactored and improved in many ways.
&gt; 1. 新增Stream数据类型。
&gt; 2. 新增Redis模块API：定时器、集群和字典API。
&gt; 3. RDB现在存储LFU和LRU信息。
&gt; 4. 集群管理器被从Ruby（redis-trib.rb）移植到C代码内部redis-cli。
&gt; 5. 新增Sorted Set命令：ZPOPMIN/MAX和(blocking variants)阻塞版本命令。
&gt; 6. 第二版主动碎片整理。
&gt; 7. HyperLogLog实现改进
&gt; 8. 更好的内存使用报告功能。
&gt; 9. 很多带有子命令的命令现在增加HELP子命令。
&gt; 10. 在客户端连接和断开频繁的情况提供更好的性能。
&gt; 11. 很多bug修复和其他随机改进。
&gt; 12. 升级Jemalloc到5.1版本。
&gt; 13. CLIENT UNBLOCK和CLIENT ID命令。
&gt; 14. 增加LOLWUT命令(快速生成一些图形的与技术使用无关的有趣命令)。
&gt; 15. 如果不是为了向后兼容API，我们不再使用&rdquo;slave&rdquo;这个词。
&gt; 16. 网络层改进
&gt; 17. Lua改进：
&gt;     - 将Lua脚本传播到从节点/AOF。
&gt;     - Lua脚本可以超时，同时在超时时可以在从节点获取到<code>-BUSY</code>的状态。
&gt; 18. 动态HZ来调整空闲CPU使用率和响应速度。(hz参数用于指定Redis定期任务的执行频率，这些任务包括关闭超时的客户端连接、主动清除过期key等)
&gt; 19. Redis核心被重构和改进了许多方面。</li>
</ol>

<h1 id="migrating-from-4-0-to-5-0">Migrating from 4.0 to 5.0</h1>

<p>Redis 4.0 is mostly a strict subset of 5.0, you should not have any problem
upgrading your application from 4.0 to 5.0. However this is a list of small
non-backward compatible changes introduced in the 5.0 release:</p>

<ul>
<li><p>redis-cli now implements the cluster management tool. We still ship the
old redis-trib, but new fixes will be implemented only in redis-cli.
See <code>redis-cli --cluster help</code> for more info.</p></li>

<li><p>The RDB format changed. Redis 5.0 is still able to read 4.0 (and all the
past versions) files, but not the other way around.</p></li>

<li><p>Certain log formats and sentences are different in Redis 5.0.</p></li>

<li><p>Now by default maxmemory is ignored by slaves, and used only once a slave
is promoted to master. It means that in setups where you want slaves to
enforce maxmemory in an independent way from the master (that will anyway
stream the key eviction DEL commands), you should active this feature manually
and make sure you understand that it breaks consistency if writes are not
always idempotent. TLDR: the new behavior is much better for 99.999% of use
cases, revert it if you really know what you are doing.</p></li>

<li><p>Scripts are only replicated by their <em>effects</em> and not by sending EVAL/EVALSHA
to slaves or the AOF log itself. This is much better in the general case
and in the future we want to totally remove the other possiblity of
propagating scripts the old way (as EVAL). However you can still turn this
back to the default via the non-documented (if not here) Redis configuration
directive &ldquo;lua-replicate-commands yes&rdquo; or
&ldquo;DEBUG lua-always-replicate-commands 0&rdquo;. However note that Redis 6 may
completely remove such feature.</p></li>

<li><p>Because of the above change related to scripts replication, certain Redis
commands that in Redis 4 had their result ordered lexicographically before
being passed to Lua via the return value of redis.call(), now have a behavior
more similar to calling the commands directly from a normal client. For
instance the ordering of elements returned by SMEMBERS or SDIFF is now
undetermined in Lua, exactly as it is by default when calling the commands
from a non-scripting context.</p></li>
</ul>

<blockquote>
<p>Redis 4.0基本是Redis 5.0的严格子集，您从4.0 升级到5.0应该没啥问题。但是5.0发布时增加了一些非向后兼容的改变：
* redis-cli现在实现集群管理工具。我们仍然发布旧的redis-trib，但新的修复将只在redis-cli中实现。使<code>redis-cli --cluster help</code>可以查看更多帮助信息。
* RDB格式变化了。Redis 5.0仍然可以读取4.0（和所有以前的版本）文件，但是反过来是读不了的。
* Redis5.0的一些日志格式和句子变化了。
* 现在 maxmemory通常被从节点忽略掉，除非从节点被提升为主节点才会被用一次。这意味着如果您想让从节点强制设置与master节点不同的maxmemory的情况下(通常会触发键删除操作)，您必须手动激活这个功能，并确保您明白如果写入不是幂等的话，这将会破坏一致性。TLDR：新的行为适用的99.999%的使用情况，除非确定要做什么，否则不要回退它。
* 脚本只会根据它们的效果进行复制，而不是发送EVAL/EVALSHA到从节点或AOF日志本身。这是一般情况下更好的的方法，并且将来我们将完全移除其他可能的方法（如EVAL）。但是您仍然可以通过非公开的配置选项&rdquo;lua-replicate-commands yes&rdquo;或&rdquo;DEBUG lua-always-replicate-commands 0&rdquo;来回退到默认值。但是Redis6可能会完全移除这个功能。
* 因为上面的改变相关的脚本复制，某些Redis命令在Redis 4中的返回值已经按字母顺序排列在Lua中，现在从Lua中直接调用这些命令的行为会和普通的客户端更为相似。例如，SMEMBERS或SDIFF的返回值在Lua中是不确定的， 因为默认是被命令从一个非脚本环境调用的。</p>
</blockquote>

    </div>
    <footer class="post-footer">
     

     <div class="post-nav">
    <div class="post-nav-next post-nav-item">
    
        <a href="http://www.shutdown.cn/post/redis5.0%E6%96%B0%E7%89%B9%E6%80%A7-%E9%9B%86%E7%BE%A4%E7%AE%A1%E7%90%86%E5%99%A8%E5%88%B0redis-cli/" rel="next" title="">
        <i class="fa fa-chevron-left"></i> 
        </a>
    
    </div>

    <div class="post-nav-prev post-nav-item">
    
        <a href="http://www.shutdown.cn/post/redis6.0-lettuce%E6%94%AF%E6%8C%81%E5%AE%A2%E6%88%B7%E7%AB%AF%E7%BC%93%E5%AD%98/" rel="prev" title="">
         <i class="fa fa-chevron-right"></i>
        </a>
    
    </div>
</div>
      
     
     
     






    </footer>
  </article>
</section>

          </div>
        </div>
        <div class="sidebar-toggle">
  <div class="sidebar-toggle-line-wrap">
    <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
  </div>
</div>
<aside id="sidebar" class="sidebar">
  <div class="sidebar-inner">

    <section class="site-overview sidebar-panel  sidebar-panel-active ">
      <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
        src="http://www.shutdown.cn/img/author.jpg"
        alt="不与天斗Domino" />
    <p class="site-author-name" itemprop="name">不与天斗Domino</p>
    <p class="site-description motion-element" itemprop="description"> 
        Programmer &amp; Architect</p>
</div>
      <nav class="site-state motion-element">
    <div class="site-state-item site-state-posts">
      <a href="http://www.shutdown.cn/post/">
        <span class="site-state-item-count">183</span>
        <span class="site-state-item-name">日志</span>
      </a>
    </div>
    <div class="site-state-item site-state-categories">    
        <a href="http://www.shutdown.cn/categories/">      
         
        <span class="site-state-item-count">15</span>
        
        <span class="site-state-item-name">分类</span>
        
        </a>
    </div>

    <div class="site-state-item site-state-tags">
        <a href="http://www.shutdown.cn/tags/">
         
        <span class="site-state-item-count">224</span>
        
        <span class="site-state-item-name">标签</span>
        </a>
    </div>
</nav>
      
      

      

      <div class="links-of-blogroll motion-element inline">
<script type="text/javascript" src="//rf.revolvermaps.com/0/0/8.js?i=&amp;m=0&amp;s=220&amp;c=ff0000&amp;cr1=ffffff&amp;f=arial&amp;l=33&amp;bv=35" async="async"></script>
</div>

    </section>
    
  </div>
</aside>

      </div>
    </main>
   
    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  <span itemprop="copyrightYear">  &copy; 
  2013 - 2023</span>
  <span class="with-love"><i class="fa fa-heart"></i></span>
  <span class="author" itemprop="copyrightHolder">天地维杰网</span>
  <span class="icp" itemprop="copyrightHolder"><a href="https://beian.miit.gov.cn/" target="_blank">京ICP备13019191号-1</a></span>
</div>
<div class="powered-by">
  Powered by - <a class="theme-link" href="http://gohugo.io" target="_blank" title="hugo" >Hugo v0.63.2</a>
</div>
<div class="theme-info">
  Theme by - <a class="theme-link" href="https://github.com/xtfly/hugo-theme-next" target="_blank"> NexT
  </a>
</div>


      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
      <span id="scrollpercent"><span>0</span>%</span>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery/index.js?v=2.1.3"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/fastclick/lib/fastclick.min.js?v=1.0.6"></script> 
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.min.js?v=1.2.1"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.ui.min.js?v=1.2.1"></script>
<script src="http://www.shutdown.cn/js/vendor/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>

<script src="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.pack.js?v=2.1.5"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/utils.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/motion.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/affix.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/schemes/pisces.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/scrollspy.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/post-details.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/toc.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/bootstrap.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {
      inlineMath: [ ['$','$'] ],
      displayMath: [ ['$$','$$'] ],
      processEscapes: true
    },
    "HTML-CSS": { fonts: ["TeX"] }
  });
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML' async></script>
</body>
</html>